<template>
    <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <h2 class="text-center  margin-bottom" v-if="queryParam.organizationSupervise == '2'">
                二级及二级以上医疗机构 48小时超时未提交预警机构
            </h2>
            <h2 class="text-center  margin-bottom" v-else>
                一级及以及以下医疗机构 五天超时未提交预警
            </h2>
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">

                    <a-col :md="6" :sm="24">
                        <a-form-item label="机构名称">
                            <a-input v-model="queryParam.customerName" placeholder="请选择机构名称"/>
                        </a-form-item>
                    </a-col>

                    <a-col :md="6" :sm="24">
                        <a-form-item label="预警类型">
                            <a-select placeholder="预警类型" v-model="queryParam.organizationSupervise">
                                <a-select-option value="1">五天未提交预警</a-select-option>
                                <a-select-option value="2">48小时未提交预警</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>

                    <a-col :md="8" :sm="24" v-if="showSelectArea">
                        <a-form-item label="区域查询">
                            <select-area ref="selectAreaRef" @change="changeArea"></select-area>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <!-- 查询区域-END -->
        <div class="table-operator" style="display: flex;justify-content: space-between;align-items: center;">
            <div>
                <a-button type="primary" @click="searchQuery" icon="search">查询数据列表</a-button>
                <a-button type="primary" @click="resetForm">重置查询</a-button>
            </div>
            <div>
                <a-button type="primary" icon="printer" v-print="'#printTableList'">打印</a-button>
                <a-button type="primary" icon="download" @click="handleMwExportXlsForImages">
                    导出Excel
                </a-button>
            </div>
        </div>

        <!-- table区域-begin -->
        <div>
            <a-table
                    ref="table"
                    size="middle"
                    bordered
                    rowKey="id"
                    :columns="columns"
                    :dataSource="dataSource"
                    :pagination="ipagination"
                    :loading="loading"
                    class="j-table-force-nowrap"
                    @change="handleTableChange"
            >
                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="imgSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                    <img v-else :src="text" height="25px" alt style="width: auto;height: 50px;"/>
                </template>
                <template slot="fileSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                    <a-button
                            v-else
                            :ghost="true"
                            type="primary"
                            icon="download"
                            size="small"
                            @click="uploadFile(text)"
                    >下载
                    </a-button>
                </template>
            </a-table>
        </div>

        <div v-show="false">
            <div id="printTableList">
                <h2 class="text-center  margin-bottom" v-if="queryParam.organizationSupervise == '2'">
                    二级及二级以上医疗机构 48小时超时未提交预警机构
                </h2>
                <h2 class="text-center  margin-bottom" v-else>
                    一级及以及以下医疗机构 五天超时未提交预警
                </h2>
                <h3>时间 ： {{new Date().FormatDate()}}</h3>
                <a-table
                        size="small"
                        bordered
                        rowKey="id"
                        :columns="printColumns"
                        :dataSource="dataSource"
                        :pagination="false"
                >
                    <template slot="htmlSlot" slot-scope="text">
                        <div style="color: black !important;" v-html="text"></div>
                    </template>
                </a-table>
            </div>
        </div>

    </a-card>
</template>

<script>
    /**
     * create by Jane
     * 废物超过48小时未收运预警
     */
    import '@/assets/less/TableExpand.less'
    import { mixinDevice } from '@/utils/mixin'
    import { JeecgListMixin } from '@/mixins/JeecgListMixin'
    import SelectArea from '@/components/Jane/SelectArea'

    import { downloadFile } from '../../../api/manage' // 模糊下拉查询

    export default {
        mixins: [JeecgListMixin, mixinDevice],
        components: {
            SelectArea
        },
        data() {
            let that = this
            return {
                description: '医废收运记录',
                fiveWeightAndBag: {},

                // 表头
                columns: [
                    {
                        title: '序号',
                        dataIndex: '',
                        key: 'rowIndex',
                        width: 60,
                        align: 'center',
                        customRender: function(t, r, index) {
                            return parseInt(index) + 1
                        }
                    },
                    // {
                    //     title: '机构编码',
                    //     align: 'center',
                    //     dataIndex: 'customerNumber'
                    // },
                    {
                        title: '机构名称',
                        align: 'center',
                        dataIndex: 'customerName'
                    },
                    {
                        title: '最后提交时间',
                        align: 'center',
                        dataIndex: 'lastCommitTime',
                        scopedSlots: { customRender: 'htmlSlot' },
                        customRender: function(value, row, index) {
                            const obj = {
                                children: < span
                            style = 'color:orange;' > { value } < /span>,
                            attrs: {
                            }
                        }
                            return obj
                        }
                    },
                    {
                        title: '机构类型',
                        align: 'center',
                        dataIndex: 'organizationSupervise',
                        scopedSlots: { customRender: 'htmlSlot' },
                        customRender: function(value, row, index) {
                            const obj = {
                                children: ' ',
                                attrs: {}
                            }
                            let info = that.$config.getOrgLevel(parseInt(value))
                            if (info) {
                                if (value == 0) {
                                    obj['children'] =
                                <
                                    span
                                    style = 'color:#32f199;' > { info['label'] } < /span>
                                } else if (value == 1) {
                                    obj['children'] =
                                <
                                    span
                                    style = 'color:#1fdbef;' > { info['label'] } < /span>
                                } else if (value == 2) {
                                    obj['children'] =
                                <
                                    span
                                    style = 'color:orange;' > { info['label'] } < /span>
                                } else if (value == 3) {
                                    obj['children'] =
                                <
                                    span
                                    style = 'color:#d42c05;' > { info['label'] } < /span>
                                }
                            }
                            return obj
                        }
                    },
                    {
                        title: '负责人',
                        align: 'center',
                        dataIndex: 'leaderName',
                        customRender: function(value, row, index) {
                            return value || ' '
                        }
                    },
                    {
                        title: '负责人电话',
                        align: 'center',
                        dataIndex: 'leaderphone',
                        customRender: function(value, row, index) {
                            return value || ' '
                        }
                    },
                    {
                        title: '机构地址',
                        align: 'center',
                        dataIndex: 'address',
                        customRender: function(value, row, index) {
                            return value || ' '
                        }
                    }
                ],
                printColumns: [
                    {
                        title: '序号',
                        dataIndex: '',
                        key: 'rowIndex',
                        width: 60,
                        align: 'center',
                        customRender: function(t, r, index) {
                            return parseInt(index) + 1
                        }
                    },
                    {
                        title: '机构名称',
                        align: 'center',
                        dataIndex: 'customerName'
                    },
                    {
                        title: '负责人',
                        align: 'center',
                        dataIndex: 'leaderName',
                        customRender: function(value, row, index) {
                            return value || ' '
                        }
                    },
                    {
                        title: '负责人电话',
                        align: 'center',
                        dataIndex: 'leaderphone',
                        customRender: function(value, row, index) {
                            return value || ' '
                        }
                    },
                    {
                        title: '机构地址',
                        align: 'center',
                        dataIndex: 'address',
                        customRender: function(value, row, index) {
                            return value || ' '
                        }
                    },
                    {
                        title: '机构类型',
                        align: 'center',
                        dataIndex: 'organizationSupervise',
                        scopedSlots: { customRender: 'htmlSlot' },
                        customRender: function(value, row, index) {
                            const obj = {
                                children: ' ',
                                attrs: {}
                            }
                            let info = that.$config.getOrgLevel(parseInt(value))
                            if (info) {
                                obj['children'] = info['label'];
                            }
                            return obj
                        }
                    },
                    {
                        title: '最后提交时间',
                        align: 'center',
                        dataIndex: 'lastCommitTime',
                    },
                ],
                url: {
                    list: '/hc/hcRecycleRecordsWaste/queryWarning',   // 小彭接口 3.0 : 查询数据列表
                    exportXlsUrlOkForImages: '/hc/hcRecycleRecordsWaste/exportWarning'  // 小彭的接口 3.0 : 导出数据信息
                },
                dictOptions: {},
                queryParam: {
                    // 1 五天未提交（一级及一级以下医疗机构）   2 重点监管（二级及二级以上医疗机构）
                    organizationSupervise: '1',
                    customerName: '',
                    cityCode: '',
                    areaCode: ''
                }
            }
        },
        created() {
            // 获取到用户登陆的信息
            let userInfo = this.$store.getters.userInfo
            if (userInfo.cityCode) {
                this.queryParam.cityCode = userInfo.cityCode
            }
            if (userInfo.areaCode) {
                this.queryParam.areaCode = userInfo.areaCode
            }
        },
        computed: {
            showSelectArea: function() {
                let state = true;
                let userInfo = this.$store.getters.userInfo
                if (userInfo.provinceCode && userInfo.cityCode && userInfo.areaCode) {
                    state = false;
                }
                return state;
            }
        },
        methods: {
            async changeArea({ area, city }) {
                if (city) {
                    this.queryParam.cityCode = city
                }
                if (area) {
                    this.queryParam.areaCode = area
                }
            },
            searchQuery: function() {
                this.loadData(1)
            },
            resetForm: function() {
                this.queryParam.organizationSupervise = '1'
                this.queryParam.customerName = ''
                let userInfo = this.$store.getters.userInfo
                this.queryParam.cityCode = userInfo.cityCode
                this.queryParam.areaCode = userInfo.areaCode
                let ref = this.$refs.selectAreaRef;
                if(ref && ref.clearSelectArea != undefined){
                    ref.clearSelectArea();
                }

                this.loadData(1)
            },
            handleMwExportXlsForImages() {
                let param = { ...this.queryParam }
                let name = `${this.queryParam.organizationSupervise == '2' ? '48小时超时未提交预警机构' : '五天超时未提交预警'}-${new Date().FormatDate()}.xls`
                downloadFile(this.url.exportXlsUrlOkForImages, name, param)
            }

        }
    }
</script>
<style scoped>
    @import '~@assets/less/common.less';
</style>
